# 需求说明：
# 1. 获取验证码： http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify
# 2. 登录： http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login
# 3. 断言：status_code, status, msg
#
# 实现要求：
# 1. 按照功能模块组织测试类，一条测试用例对应一个测试方法
# 2. 添加断言：响应状态码/success/code/message
# 3. 封装测试套件批量执行用例
# 4. 生成测试报告
# login_data = {
#             "username": "13488888888",
#             "password": "123456",
#             "verify_code": "8888"
#         }

import requests

class Test_logIn:
    def setup_class(self):
        self.session = requests.session()

    def teardown_class(self):
        self.session.close()

    def test01_loginSuccessful(self):
        urlgetPictures = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify"

        response = self.session.get(url=urlgetPictures)
        print(response.status_code)
        assert response.status_code == 200

        urllogIn = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        login_data = {
            "username": "13488888888",
            "password": "123456",
            "verify_code": "8888"
        }
        response = self.session.post(url=urllogIn, data=login_data)
        print(response.json())
        assert response.status_code == 200
        assert response.json()["msg"]=="登陆成功"
        assert response.json()["status"]==1


    def test02_accountError(self):
        urlgetPictures = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify"

        response = self.session.get(url=urlgetPictures)
        print(response.status_code)
        assert response.status_code == 200

        urllogIn = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        login_data = {
            "username": "5789342785",
            "password": "123456",
            "verify_code": "8888"
        }
        response = self.session.post(url=urllogIn, data=login_data)
        print(response.json())
        assert response.status_code == 200
        assert response.json()["msg"] == "账号不存在!"
        assert response.json()["status"] == -1



    def test03_wrongPassword(self):
        urlgetPictures = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify"

        response = self.session.get(url=urlgetPictures)
        print(response.status_code)
        assert response.status_code == 200

        urllogIn = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        login_data = {
            "username": "13488888888",
            "password": "123451",
            "verify_code": "8888"
        }
        response = self.session.post(url=urllogIn, data=login_data)
        print(response.json())
        assert response.status_code == 200
        assert response.json()["msg"] == "密码错误!"
        assert response.json()["status"] == -2